﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NCS_CS
{
    class Conversion
    {
        public static double Val(string InputStr)
        {

            double r;
            System.Double.TryParse(InputStr,out r);
            return r;
        }

        private static double HexOrOctValue(string InputStr, int i)
        {
            int num2;
            long num5=0;
            int num = 0;
            int length = InputStr.Length;
            char ch = InputStr[i];
            i++;
            if ((ch != 'H') && (ch != 'h'))
            {
                if ((ch != 'O') && (ch != 'o'))
                {
                    return 0.0;
                }
                while ((i < length) && (num < 0x16))
                {
                    ch = InputStr[i];
                    i++;
                    char ch3 = ch;
                    if ((((ch3 != '\t') && (ch3 != '\n')) && (ch3 != '\r')) && ((ch3 != ' ') && (ch3 != '　')))
                    {
                        if (ch3 == '0')
                        {
                            if (num == 0)
                            {
                                continue;
                            }
                            num2 = 0;
                        }
                        else
                        {
                            if ((ch3 < '1') || (ch3 > '7'))
                            {
                                break;
                            }
                            num2 = ch - '0';
                        }
                        if (num5 >= 0x1000000000000000L)
                        {
                            num5 = (num5 & 0xfffffffffffffffL) * 8L;
                            num5 |= 0x1000000000000000L;
                        }
                        else
                        {
                            num5 *= 8L;
                        }
                        num5 += num2;
                        num++;
                    }
                }
            }
            else
            {
                while ((i < length) && (num < 0x11))
                {
                    ch = InputStr[i];
                    i++;
                    char ch2 = ch;
                    if ((((ch2 != '\t') && (ch2 != '\n')) && ((ch2 != '\r') && (ch2 != ' '))) && (ch2 != '　'))
                    {
                        if (ch2 == '0')
                        {
                            if (num == 0)
                            {
                                continue;
                            }
                            num2 = 0;
                        }
                        else if ((ch2 >= '1') && (ch2 <= '9'))
                        {
                            num2 = ch - '0';
                        }
                        else if ((ch2 >= 'A') && (ch2 <= 'F'))
                        {
                            num2 = ch - '7';
                        }
                        else
                        {
                            if ((ch2 < 'a') || (ch2 > 'f'))
                            {
                                break;
                            }
                            num2 = ch - 'W';
                        }
                        if ((num == 15) && (num5 > 0x7ffffffffffffffL))
                        {
                            num5 = (num5 & 0x7ffffffffffffffL) * 0x10L;
                            num5 |= -9223372036854775808L;
                        }
                        else
                        {
                            num5 *= 0x10L;
                        }
                        num5 += num2;
                        num++;
                    }
                }
                if (num == 0x10)
                {
                    i++;
                    if (i < length)
                    {
                        ch = InputStr[i];
                    }
                }
                if (num <= 8)
                {
                    if ((num > 4) || (ch == '&'))
                    {
                        if (num5 > 0x7fffffffL)
                        {
                            num5 = -2147483648L + (num5 & 0x7fffffffL);
                        }
                    }
                    else if (((num > 2) || (ch == '%')) && (num5 > 0x7fffL))
                    {
                        num5 = -32768L + (num5 & 0x7fffL);
                    }
                }
                switch (ch)
                {
                    case '%':
                        num5 = (short)num5;
                        break;

                    case '&':
                        num5 = (int)num5;
                        break;
                }
                return (double)num5;
            }
            if (num == 0x16)
            {
                i++;
                if (i < length)
                {
                    ch = InputStr[i];
                }
            }
            if (num5 <= 0x100000000L)
            {
                if ((num5 > 0xffffL) || (ch == '&'))
                {
                    if (num5 > 0x7fffffffL)
                    {
                        num5 = -2147483648L + (num5 & 0x7fffffffL);
                    }
                }
                else if (((num5 > 0xffL) || (ch == '%')) && (num5 > 0x7fffL))
                {
                    num5 = -32768L + (num5 & 0x7fffL);
                }
            }
            switch (ch)
            {
                case '%':
                    num5 = (short)num5;
                    break;

                case '&':
                    num5 = (int)num5;
                    break;
            }
            return (double)num5;
        }

 

 


 

    }

}
